var request = require("request");
var assert = require("assert");
var expect = require("chai").expect;
var should = require("chai").should();
var underscore = require("underscore");


var config = require("../config/index");

describe.skip('engine', function () {
    describe('twitter#get', function () {
        it('should be found specify message in response', function (done) {

            var messageNode = "Washington";

            var params = {
                "serviceType": "twitter",
                "serviceRealm": "global",
                "serviceVersion": 0,
                "op": "get",
                "paramSet": {
                    "data": messageNode
                }
            };

            var paramStr = JSON.stringify(params);

            var options = {
                url: 'http://172.22.200.35:8000/api?m=' + paramStr,
                headers: {
                    'User-Agent': 'request'
                }
            };

            request(options, function (error, response, body) {
                if (error) throw error;

                console.log(error);

                var res = JSON.parse(body);

                console.log(res);

                assert.equal(response.statusCode, 200);

                res.should.have.messageNode;
                done();
            });

        });

        it('should be return "There is no data for request", in case unknown data', function (done) {

            var messageNode = "18989";

            var params = {
                "serviceType": "twitter",
                "serviceRealm": "global",
                "serviceVersion": 0,
                "op": "get",
                "paramSet": {
                    "data": messageNode
                }
            };

            var paramStr = JSON.stringify(params);

            var options = {
                url: 'http://172.22.200.35:8000/api?m=' + paramStr,
                headers: {
                    'User-Agent': 'request'
                }
            };

            request(options, function (error, response, body) {
                if (error) throw error;

                console.log(error);

                var res = JSON.parse(body);

                console.log(res);

                var expectedErrorMessage = "There is no data for request: " + messageNode + "";

                var actualErrorDetails = res.errorSet[0].details;

                assert.equal(expectedErrorMessage, actualErrorDetails);

                done();

            });

        });

        it('should be return data', function (done) {

            var messageNode = "";

            var params = {
                "serviceType": "twitter",
                "serviceRealm": "global",
                "serviceVersion": 0,
                "op": "get",
                "paramSet": {
                    "data": messageNode
                }
            };

            var paramStr = JSON.stringify(params);

            var options = {
                url: 'http://172.22.200.35:8000/api?m=' + paramStr,
                headers: {
                    'User-Agent': 'request'
                }
            };

            request(options, function (error, response, body) {
                if (error) throw error;

                console.log(error);

                var res = JSON.parse(body);

                console.log(res);

                var resMessage = "virginia";

                var actualResult = res.resultSet;

                actualResult.forEach(function (item) {
                    if (item.text === resMessage) {
                        done();
                    }

                });
            });

        });
        it('should be return service status', function (done) {

            var params = {
                "serviceType": "twitter",
                "serviceRealm": "global",
                "serviceVersion": 0,
                "op": "serviceStatus"
            };

            var paramStr = JSON.stringify(params);

            var options = {
                url: 'http://172.22.200.35:8000/api?m=' + paramStr,
                headers: {
                    'User-Agent': 'request'
                }
            };

            request(options, function (error, response, body) {
                if (error) throw error;

                console.log(error);

                var res = JSON.parse(body);

                console.log(res);

                var actualResult = res.resultSet.status.code;

                console.log(actualResult);

                assert.equal("ok", actualResult);

                 done();

                });
            });

        it('should save without error 2', function (done) {

            var options = {
                url: 'http://172.22.200.35:8000/acs.html',
                headers: {
                    'User-Agent': 'request'
                }
            };

            request(options, function (error, response, body) {
                if (error) throw error;
                if (response.statusCode === 200) {
                    done();

                }

            });
        });
    });
});
